package com.ileaf.java8;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * @author Lianlb
 * @date 2019-05-06 15:00
 */
public class ListUtil {

    public static void main(String[] args) {
        List<Org> list = new ArrayList<>();
        list.add(new Org("1", "001"));
        list.add(new Org("2", "001"));
        list.add(new Org("3", "001"));
        list.add(new Org("4", "001"));

        Optional<Org> any = list.stream().filter(o -> "5".equals(o.getId())).findAny();
        if (any.isPresent()) {
            Org org = any.get();
            System.out.println(org);
        }

        List<Org> collect = list.stream().filter(m -> "3".equals(m.getId())).collect(Collectors.toList());
        System.out.println(collect);

        Object[] array = list.toArray();
        for (Object o : array) {
            System.out.println(o);
        }

    }

    static class Org {
        private String id;
        private String innercode;

        public Org(String id, String innercode) {
            this.id = id;
            this.innercode = innercode;
        }

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        public String getInnercode() {
            return innercode;
        }

        public void setInnercode(String innercode) {
            this.innercode = innercode;
        }

        @Override
        public String toString() {
            return "Org{" +
                    "id='" + id + '\'' +
                    ", innercode='" + innercode + '\'' +
                    '}';
        }
    }
}
